(function (vc, vm) {
    vc.extends({
        data: {
            editHousekeepingFeeTypeInfo: {
                feeTypeCd: '',
                typeName: '',
                isShow: '',
                isShows: [],
                remark: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editHousekeepingFeeType', 'openEditHousekeepingFeeTypeModal', function (_params) {
                $that.refreshEditHousekeepingFeeTypeInfo();
                vc.getDict('housekeeping_type', "is_show", function (_data) {
                    $that.editHousekeepingFeeTypeInfo.isShows = _data;
                });
                $('#editHousekeepingFeeTypeModel').modal('show');
                vc.copyObject(_params, $that.editHousekeepingFeeTypeInfo);
            });
        },
        methods: {
            editHousekeepingFeeTypeValidate: function () {
                return vc.validate.validate({
                    editHousekeepingFeeTypeInfo: $that.editHousekeepingFeeTypeInfo
                }, {
                    'editHousekeepingFeeTypeInfo.typeName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "类型名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "类型名称太长"
                        }
                    ],
                    'editHousekeepingFeeTypeInfo.isShow': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "是否展示不能为空"
                        }
                    ],
                    'editHousekeepingFeeTypeInfo.feeTypeCd': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "费用类型编码不能为空"
                        }
                    ]
                });
            },
            editHousekeepingFeeType: function () {
                if (!$that.editHousekeepingFeeTypeValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.editHousekeepingFeeTypeInfo.shopId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/housekeepingFeeType/updateHousekeepingFeeType',
                    JSON.stringify($that.editHousekeepingFeeTypeInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editHousekeepingFeeTypeModel').modal('hide');
                            vc.emit('housekeepingFeeType', 'listHousekeepingFeeType', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditHousekeepingFeeTypeInfo: function () {
                $that.editHousekeepingFeeTypeInfo = {
                    feeTypeCd: '',
                    typeName: '',
                    isShow: '',
                    isShows: [],
                    remark: ''
                }
            }
        }
    });
})(window.vc, window.vc.component);
